package com.sort;

import java.util.Arrays;
import java.util.Date;

/**
 * @BelongsProject: DataStructures
 * @BelongsPackage: com.sort
 * @Author: 江岸
 * @CreateTime: 2021-01-27 22:58
 * @Description: 冒泡排序
 */
public class BubbleSort {

    public static void main(String[] args) {
//        int[] arr = {5,42,78,11,37,894,131,-1};
        int[] arr = new int[80000];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int) (Math.random()*800000);
        }
        long l = System.currentTimeMillis();
        for (int i=0;i<arr.length;i++){
            boolean flag = true;
            for (int j=0;j<arr.length-1-i;j++){
                if (arr[j]>arr[j+1]){
                    //位运算交换两个数
                    arr[j] = arr[j]^arr[j+1];
                    arr[j+1] = arr[j]^arr[j+1];
                    arr[j] = arr[j]^arr[j+1];
                    flag = false;
                }
            }
            if (flag){
                break;
            }
        }
       // System.out.println(Arrays.toString(arr));
        long l1 = System.currentTimeMillis();
        System.out.println((l1-l)/1000);

    }
}
